<template lang="pug">
.switch-lesson
  .modal-dialog.modal__overwrite(role='document', v-show="show")
    .modal-content
      .modal-header
        h5.modal-title 上传
        button.close(type='button', data-dismiss='modal', aria-label='Close')
          span(aria-hidden='true', @click="close") ×
      .modal-body
        form.form
          .form-group.row
            label.col-sm-3.col-form-label
              | 章节：
            .col-sm-9
              input.form-control-plaintext(type="text", readonly="true", value="1.4有理数")
          .form-group.row
            label.col-sm-3.col-form-label
              | 文件：
            .col-sm-9
              input.form-control(type='file', id="video") 
          .form-group.row
            label.col-sm-3.col-form-label
              | 名称：
            .col-sm-9
              input.form-control(type="text", v-model="videoName")
              .invalid-feedback.d-block 注：文字大小500M以内，支持MP4  H264 swf flv格式播放
          .form-group.row
            .col-sm-3
            .col-sm-9
              .form-check
                label.form-check-label
                  input.form-check-input(type='checkbox', v-model="isShare")
                  | 共享：（共享后同年级老师都能浏览资源）
          .modal__btn__group
            button.btn.btn-sm.btn-outline-primary.btn__submit(@click="submit") 确定
            button.btn.btn-sm.btn-outline-primary(@click="close") 取消
          
</template>
<style lang="scss" scoped>
.form {
  margin-top: 210px;
  margin-bottom: 60px;
}
.modal__btn__group {
  margin-top: 200px;
}
.form-check-input {
  margin-right: 5px;
}
</style>

<script>
import { mapState } from 'vuex'
import api from 'api/teacher/lession'
export default {
  data () {
    return {
      isShare: false,
      videoName: ''
    }
  },
  computed: mapState({
    show: state => state.modal.teacherAddLession,
    isModify: state => state.bridge.lession.type === 'modify',
    item: state => state.bridge.lession.data
  }),
  methods: {
    close () {
      this.$store.commit('hide', 'teacherAddLession')
    },
    submit () {
      /* global FormData */
      var data = new FormData()
      data.append('video', $('#video')[0].files[0])
      data.append('catelogid', '142618295059611648')
      data.append('teacherName', '教师aaa')
      data.append('teacherid', '120176175841542144')
      data.append('videoName', this.videoName)
      data.append('isShare', this.isShare ? '1' : '0')
      api.postLession(data).then((response) => {
        if (response.data.success) {
          this.$store.commit('changeAlert', {
            type: true
          })
        } else {
          this.$store.commit('changeAlert', {
            type: false
          })
        }
        this.$store.commit('show', 'alert')
      })
    }
  }
}
</script>